<template>
  <div class="app-container">
    <el-container>
      <el-aside width="450px">
        <el-container>
          <el-header height="450px">
            <h3>待诊患者</h3>
            <hr />
            <el-form
              :model="patient"
              :inline="true"
              :rules="mrules"
              ref="form"
              label-width="40px"
              class="demo-form"
            >
              <el-form-item label="姓名" prop="pname">
                <el-input v-model="patient.pname"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="getPatientListByPname"
                  >查询</el-button
                >
                <el-button type="primary" @click="resetForm('form')"
                  >重置</el-button
                >
              </el-form-item>
            </el-form>
            <el-table
              :data="patientListByStatus1"
              @row-dblclick="rowDblclickPatientStatus1Row"
              style="width: 100%"
              :height="300"
            >
              <el-table-column prop="pname" label="姓名" width="150px">
              </el-table-column>
              <el-table-column prop="pid" label="病历号" width="150px">
              </el-table-column>
              <el-table-column prop="pstatus" label="状态" width="100px">
              </el-table-column>
            </el-table>
          </el-header>
          <el-main>
            <h3>已诊患者</h3>
            <hr />
            <el-table
              :data="patientListByStatus3"
              @row-dblclick="rowDblclickPatientStatus3Row"
              style="width: 100%"
              :height="300"
            >
              <el-table-column prop="pname" label="姓名" width="150px">
              </el-table-column>
              <el-table-column prop="pid" label="病历号" width="150px">
              </el-table-column>
              <el-table-column prop="pstatus" label="状态" width="100px">
              </el-table-column>
            </el-table>
          </el-main>
        </el-container>
      </el-aside>
      <el-main width="100%">
        <el-tabs>
          <el-tab-pane label="病历首页">
            <el-form
              :model="medicalrecord"
              :rules="mrules"
              ref="medicalrecord"
              label-width="100px"
              class="demo-medicalrecord"
            >
              <el-col :span="6">
                <el-form-item label="患者姓名">
                  <el-input
                    v-model="patientBean.patient.pname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="患者年龄">
                  <el-input
                    v-model="patientBean.patient.age"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊科室">
                  <el-input
                    v-model="patientBean.dept.deptname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊医生">
                  <el-input
                    v-model="patientBean.doctor.dname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-form-item label="病历描述" prop="description">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.description"
                ></el-input>
              </el-form-item>
              <el-form-item label="既往病史" prop="medicalhistory">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.medicalhistory"
                ></el-input>
              </el-form-item>
              <el-form-item label="家族病史" prop="familyhistory">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.familyhistory"
                ></el-input>
              </el-form-item>
              <el-form-item label="初步结果" prop="initialresult">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.initialresult"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm('medicalrecord')"
                  >立即提交</el-button
                >
                <el-button @click="resetForm1('medicalrecord')">重置</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="检验管理">
            <el-form label-width="100px">
              <el-col :span="6">
                <el-form-item label="患者姓名">
                  <el-input
                    v-model="patientBean.patient.pname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="患者年龄">
                  <el-input
                    v-model="patientBean.patient.age"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊科室">
                  <el-input
                    v-model="patientBean.dept.deptname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊医生">
                  <el-input
                    v-model="patientBean.doctor.dname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <h3>检验项目{{checkInspectitemTableList}}</h3>
              <el-table
                :data="checkInspectitemTableList"
                ref="inspectitemTable"
                :row-class-name="tableRowClassName"
                stripe
                style="width: 100%"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="id" width="120">
                  <template slot-scope="scope">{{ scope.row.id }}</template>
                </el-table-column>
                <el-table-column
                  prop="inspectname"
                  label="检验名称"
                  width="120"
                >
                </el-table-column>
                <el-table-column
                  prop="price"
                  label="检验价格"
                  show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column label="数量" prop="amount">
                  <templete slot-scope="scope">
                    <el-input
                      type="number"
                      @input="amountInput(scope.$index)"
                      v-model="scope.row.amount"
                    >
                    </el-input>
                  </templete>
                </el-table-column>
                <el-table-column label="操作">
                  <templete slot-scope="scope">
                    <el-button
                      size="mini"
                      type="danger"
                      @click="handleInspectitemDelete(scope.$index, scope.row)"
                    >
                      删除</el-button
                    >
                  </templete>
                </el-table-column>
              </el-table>
              <h3>总价:{{ totalPrice | showPrice }}</h3>
              <h3>项目操作</h3>

              <el-form-item>
                <el-button type="primary" @click="openDialogInspectitemVisible"
                  >新增项目</el-button
                >
                <el-button type="primary" @click="submitInspectiteMrecord"
                  >开立项目</el-button
                >
                <el-button type="primary" @click="deleteTableList"
                  >删除项目</el-button
                >
                <el-button @click="resetForm2">重置项目</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
           <el-tab-pane label="检查管理">
            <el-form label-width="100px">
              <el-col :span="6">
                <el-form-item label="患者姓名">
                  <el-input
                    v-model="patientBean.patient.pname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="患者年龄">
                  <el-input
                    v-model="patientBean.patient.age"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊科室">
                  <el-input
                    v-model="patientBean.dept.deptname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊医生">
                  <el-input
                    v-model="patientBean.doctor.dname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <h3>检查项目</h3>
              <el-table
                :data="selectcheckitemTableList"
                ref="checkitemTable"
                :row-class-name="tableRowClassName2"
                stripe
                style="width: 100%"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="id" width="120">
                  <template slot-scope="scope">{{ scope.row.id }}</template>
                </el-table-column>
            
                <el-table-column
                  prop="itemname"
                  label="检查名称"
                  width="120"
                >
                </el-table-column>
                <el-table-column
                  prop="price"
                  label="检查价格"
                  show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column label="数量" prop="amount">
                  <templete slot-scope="scope">
                    <el-input
                      type="number"
                      @input="amountCheckInput(scope.$index)"
                      v-model="scope.row.amount"
                    >
                    </el-input>
                  </templete>
                </el-table-column>
                <el-table-column label="操作">
                  <templete slot-scope="scope">
                    <el-button
                      size="mini"
                      type="danger"
                      @click="handleCheckitemDelete(scope.$index, scope.row)"
                    >
                      删除</el-button
                    >
                  </templete>
                </el-table-column>
              </el-table>
              <h3>总价:{{ totalPrice2 | showPrice2 }}</h3>
              <h3>项目操作</h3>

              <el-form-item>
                <el-button type="primary" @click="openDialogCheckitemVisible"
                  >新增项目</el-button
                >
                <el-button type="primary" @click="submitCheckiteMrecord"
                  >开立项目</el-button
                >
                <el-button type="primary" @click="deleteTableList1"
                  >删除项目</el-button
                >
                <el-button @click="resetForm4">重置项目</el-button>
                  </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="最终确诊">
            <el-form
              :model="medicalrecord"
              :rules="mrules"
              ref="medicalrecord"
              label-width="100px"
              class="demo-medicalrecord"
            >
              <el-col :span="6">
                <el-form-item label="患者姓名">
                  <el-input
                    v-model="patientBean.patient.pname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="患者年龄">
                  <el-input
                    v-model="patientBean.patient.age"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊科室">
                  <el-input
                    v-model="patientBean.dept.deptname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="看诊医生">
                  <el-input
                    v-model="patientBean.doctor.dname"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-form-item label="病历描述" prop="description">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.description"
                ></el-input>
              </el-form-item>
              <el-form-item label="既往病史" prop="medicalhistory">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.medicalhistory"
                ></el-input>
              </el-form-item>
              <el-form-item label="家族病史" prop="familyhistory">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.familyhistory"
                ></el-input>
              </el-form-item>
               <el-form-item label="检查结果" prop="result">
                <el-input
                  type="textarea"
                  rows="4"
                  v-model="medicalrecord.result"
                ></el-input>
              </el-form-item>
              <el-form-item label="最终确诊" prop="finalresult">
                <el-input
                  type="textarea"
                  rows="5"
                  v-model="medicalrecord.finalresult"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitGlobal('medicalrecord')"
                  >最终确诊</el-button
                >
                <el-button @click="resetForm3('medicalrecord')">重置</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </el-main>
    </el-container>
    <!-- 弹出检验项目列表 dialogInspectitemVisible -->
    <el-dialog
      title="检验项目"
      :visible.sync="dialogInspectitemVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-col :span="6">
        <el-input
          size="20px"
          v-model="inspectname"
          placeholder="检验名称"
        ></el-input>
      </el-col>
      <el-button type="primary" @click="onGetInspectitemList">查询</el-button>
      <el-table
        ref="multipleTable"
        :data="inspectitemList"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="id" width="120">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column prop="inspectname" label="检验名称" width="120">
        </el-table-column>
        <el-table-column prop="price" label="检验价格" show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogInspectitemVisible = false">取 消</el-button>
        <el-button type="primary" @click="addCheckInspectitem">确 定</el-button>
      </div>
    </el-dialog>
      <!-- 弹出检查项目列表 dialogCheckitemVisible -->
    <el-dialog
      title="检查项目"
      :visible.sync="dialogCheckitemVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-col :span="6">
        <el-input
          size="20px"
          v-model="itemname"
          placeholder="检查名称"
        ></el-input>
      </el-col>
      <el-button type="primary" @click="onGetCheckitemList">查询</el-button>
      <el-table
        ref="multipleTable1"
        :data="checkitemList"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="id" width="120">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column prop="itemname" label="检查名称" width="120">
        </el-table-column>
        <el-table-column prop="price" label="检查价格" show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogCheckitemVisible = false">取 消</el-button>
        <el-button type="primary" @click="addCheckitem">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import user from "@/api/user";
import patient from "@/api/patient";
import medicalrecordapi from "@/api/medicalrecordapi";
export default {
  data() {
    return {
      medicalrecord: {
        pid: "",
        description: "",
        medicalhistory: "",
        familyhistory: "",
        initialresult: "",
        finalresult: "",
        result:""
      },
      patientBean: {
        patient: {
          pid: "",
          pname: "",
          age: "",
        },
        dept: {
          deptname: "",
        },
        doctor: {
          dname: "",
        },
        inspectiteMrecords:[],
        checkitemMrecords:[]
      },
      patient: {
        pid: "",
        pname: "",
        sex: "",
        age: "",
        address: "",
        createdate: "",
        operatedate: "",
        deptname: "",
        levelname: "",
        cost: 0,
      },
      mrules: {
        description: [
          { required: true, message: "请填写病历描述", trigger: "blur" },
        ],
        medicalhistory: [
          { required: true, message: "请填写既往病史", trigger: "blur" },
        ],
        familyhistory: [
          { required: true, message: "请填写家族病史", trigger: "blur" },
        ],
        initialresult: [
          { required: true, message: "请填写初步结果", trigger: "blur" },
        ],
         result: [
          { required: true, message: "请填写检查结果", trigger: "blur" },
        ],
        finalresult: [
          { required: true, message: "请填写最终结果", trigger: "blur" },
        ],
      },
      patientListByStatus1: [],
      patientListByStatus3: [],
      dialogInspectitemVisible: false,
      dialogCheckitemVisible: false,
      inspectitemList: [],
      inspectname: "",
      price: "",
      itemname:"",
      checkInspectitemList: [],
      checkInspectitemTableList: [], //医生选择列表,以及向后台提交
       checkitemList:[],
       selectcheckitemTableList: [],
       selectCheckitemList: [],
    };
  },
  methods: {
    //提交患者诊断表单
    submitForm(medicalrecord) {
      this.$refs[medicalrecord].validate((valid) => {
        if (valid) {
          let pname = this.patientBean.patient.pname;
          if (pname == "") {
            this.$notify,
              error({
                title: "错误",
                message: "请输入患者信息",
              });
          } else {
            medicalrecordapi
              .saveMedicalrecord(this.medicalrecord)
              .then((res) => {
                if (res.message == "添加纪录成功") {
                  this.$notify({
                    title: "成功",
                    message: "添加记录成功",
                    type: "success",
                  });
                } else {
                  this.$notify({
                    title: "失败",
                    message: "添加记录失败",
                  });
                }
              });
          }
          console.log(this.medicalrecord);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //病例首页待诊患者查询重置
    resetForm(form) {
      this.$refs[form].resetFields();
      this.getPatientListByStatus1();
      this.getPatientListByStatus3();
    },
    //病例首页重置
    resetForm1(medicalrecord) {
       this.patientBean.patient = {};
      this.patientBean.dept = {};
      this.patientBean.doctor = {};
      this.medicalrecord = {};
      this.getPatientListByStatus1();
      this.getPatientListByStatus3();
    },
    //检验项目重置
    resetForm2(medicalrecord) {
       this.patientBean.patient = {};
      this.patientBean.dept = {};
      this.patientBean.doctor = {};
      let length = this.checkInspectitemTableList.length;
      while (length >= 0) {
        this.checkInspectitemTableList.splice(--length, 1);
      }
    },
       //确诊重置
      resetForm4(medicalrecord) {
      this.patientBean.patient = {};
      this.patientBean.dept = {};
      this.patientBean.doctor = {};
      let len = this. selectcheckitemTableList.length;
      while (len >= 0) {
        this. selectcheckitemTableList.splice(--len, 1);
      }
    },
    resetForm3(medicalrecord) {
      this.resetForm1(medicalrecord);
      this.resetForm2(medicalrecord);
      this.resetForm4(medicalrecord);
    },
    //检查项目重置
    //获取待诊患者列表
    getPatientListByStatus1() {
      patient
        .getPatientListByStatus1()
        .then((res) => {
          console.log(res);
          this.patientListByStatus1 = res.data.patientListByStatus1;
        })
        .catch((res) => {
          this.$notify.error({
            title: "错误",
            message: "查询待诊患者失败",
          });
        });
    },
    //获取已诊患者列表
    getPatientListByStatus3() {
      patient
        .getPatientListByStatus3()
        .then((res) => {
          console.log(res);
          this.patientListByStatus3 = res.data.patientListByStatus3;
        })
        .catch((res) => {
          this.$notify.error({
            title: "错误",
            message: "查询已诊患者失败",
          });
        });
    },
    //待诊患者点击事件
    rowDblclickPatientStatus1Row(row, column) {
      patient.getPatientBeanByPatientId(row.pid).then((res) => {
        console.log(res.data);
        this.patientBean = res.data.patientBean;
        this.medicalrecord.pid = res.data.patientBean.patient.pid;
      });
    },
    //已诊患者点击事件
    rowDblclickPatientStatus3Row(row, column) {
      patient.getPatientBeanByPatientId(row.pid).then((res) => {
        console.log(res.data);
        this.patientBean = res.data.patientBean;
        this.medicalrecord.pid=row.pid;
        this.medicalrecord.description=this.patientBean.medicalrecord.description;
        this.medicalrecord.medicalhistory=this.patientBean.medicalrecord.medicalhistory;
         this.medicalrecord.familyhistory=this.patientBean.medicalrecord.familyhistory;
        this.medicalrecord.finalresult=this.patientBean.medicalrecord.finalresult;
        this.medicalrecord.initialresult=this.patientBean.medicalrecord.initialresult;
        this.medicalrecord.result=this.patientBean.medicalrecord.result;

       this.checkInspectitemTablelist = this.patientBean.inspectiteMrecords;
       console.log(this.checkInspectitemTablelist);
        let i = 0;
        this.patientBean.inspectiteMrecords.forEach((item) => {
          console.log(item);
          //赋值
          // this.checkInspectitemTablelist[i].price = item.inspectitem.price;
          // this.checkInspectitemTablelist[i].inspectname = item.inspectitem.inspectname;
          // this.checkInspectitemTablelist[i].amount = item.inspectitem.amount;
          i++;
        });
      });
    },
    //待诊患者通过名字查询
    getPatientListByPname() {
      let pname = this.patient.pname;
      patient
        .getPatientListByPname(pname)
        .then((res) => {
          console.log(res);
          this.patientListByStatus1 = res.data.patientListByStatus1;
        })
        .catch((res) => {
          this.$notify.error({
            title: "错误",
            message: "查询待诊患者失败",
          });
        });
    },
    onGetInspectitemList() {
      this.getInspectitemList();
    },
    onGetCheckitemList() {
      this.getCheckitemList();
    },
    //打开检验项目
    openDialogInspectitemVisible() {
      this.dialogInspectitemVisible = true;
      this.getInspectitemList();
    },
    //打开检查项目
    openDialogCheckitemVisible() {
      this.dialogCheckitemVisible = true;
      this.getCheckitemList();
    },
    //获取检验项目列表
    getInspectitemList() {
      let arr = new Array();
      for (let i = 0; i < this.checkInspectitemList.length; i++) {
        let item = this.checkInspectitemList[i];
        arr.push(item.id);
      }
      let inspectids = arr.join(",");
      let inspectname = this.inspectname;
      medicalrecordapi
        .getInspectitemList(inspectids, inspectname)
        .then((res) => {
          this.inspectitemList = res.data.inspectitemList;
        });
    },
    //获取检查项目列表
    getCheckitemList() {
      let arr = new Array();
      for (let i = 0; i < this. selectCheckitemList.length; i++) {
        let item = this. selectCheckitemList[i];
        arr.push(item.id);
      }
      let cids = arr.join(",");
      let itemname = this.itemname;
      medicalrecordapi
        .getCheckitemList(cids,itemname)
        .then((res) => {
          this.checkitemList = res.data.checkitemList;
        });
    },
    //选择检验项目，添加到页面表格
    addCheckInspectitem() {
      this.dialogInspectitemVisible = false;
      this.checkInspectitemTableList = this.checkInspectitemList;
      this.$refs.multipleTable.selection.forEach((item) => {
        this.checkInspectitemList.push(item);
      });
    },
     //选择检查项目，添加到页面表格
    addCheckitem() {
      this.dialogCheckitemVisible = false;
      this.selectcheckitemTableList = this.selectCheckitemList;
      this.$refs.multipleTable1.selection.forEach((item) => {
        this.selectCheckitemList.push(item);
      });
    },
    //检验项目页面列表的删除按钮
    handleInspectitemDelete(index, row) {
      this.checkInspectitemTableList.splice(index, 1);
    },
     //检验项目页面列表的删除按钮
    handleCheckitemDelete(index, row) {
      this. selectcheckitemTableList.splice(index, 1);
    },
    tableRowClassName({ row, rowIndex }) {
     // console.log(rowIndex + "---");
      //把每一行的索引放进row
      row.index = rowIndex;
    },
      tableRowClassName2({ row, rowIndex }) {
      //console.log(rowIndex + "---");
      //把每一行的索引放进row
      row.index = rowIndex;
    },
    //删除选中检验项目
    deleteTableList() {
      let arr = new Array();
      this.$refs.inspectitemTable.selection.forEach((item) => {
        arr.push(item.index);
      });
      arr.reverse();
      console.log(arr + "---");
      arr.forEach((i) => {
        this.checkInspectitemTableList.splice(i, 1);
      });
    },
     //删除选中检查项目
    deleteTableList1() {
      let arr = new Array();
      this.$refs.checkitemTable.selection.forEach((item) => {
        arr.push(item.index);
      });
      arr.reverse();
      console.log(arr + "---");
      arr.forEach((i) => {
        this. selectcheckitemTableList.splice(i, 1);
      });
    },
    //检验项目的单个数量
    amountInput(index) {
      if (this.checkInspectitemTableList[index].amount < 1) {
        this.$notify({
          title: "提示",
          message: "数量不能小于1",
          type: "success",
        });
        this.checkInspectitemTableList[index].amount = 1;
        return;
      }
    },
    //检验项目的单个数量
    amountCheckInput(index) {
      if (this. selectcheckitemTableList[index].amount < 1) {
        this.$notify({
          title: "提示",
          message: "数量不能小于1",
          type: "success",
        });
        this. selectcheckitemTableList[index].amount = 1;
        return;
      }
    },
    //提交检验项目
    submitInspectiteMrecord() {
      let pname = this.patientBean.patient.pname;
      if (pname == "") {
        this.$notify.error({
          title: "错误",
          message: "请输入患者信息",
        });
        return false;
      } else if (this.checkInspectitemTableList.length == 0) {
        this.$notify.error({
          title: "错误",
          message: "请输入检验项目",
        });
        return false;
      } else {
         //console.log("****"+this.checkInspectitemTableList)
        medicalrecordapi
          .saveInspectiteMrecord(
            this.checkInspectitemTableList,
            this.patientBean.patient.pid
          )
          .then((res) => {
            if (res.message == "数据为空") {
              this.$notify.error({
                title: "失败",
                message: "检验数据为空",
              });
            } else if (res.message == "提交检验项目失败") {
              this.$notify.error({
                title: "失败",
                message: "提交检验项目失败",
              });
            } else {
              this.$notify({
                title: "成功",
                message: "提交检验项目成功",
              });
            }
          });
      }
    },
    //提交检查项目
    submitCheckiteMrecord() {
      let pname = this.patientBean.patient.pname;
      if (pname == "") {
        this.$notify.error({
          title: "错误",
          message: "请输入患者信息",
        });
        return false;
      } else if (this. selectcheckitemTableList.length == 0) {
        this.$notify.error({
          title: "错误",
          message: "请输入检验项目",
        });
        return false;
      } else {
        medicalrecordapi
          .saveCheckiteMrecord(
            this. selectcheckitemTableList,
            this.patientBean.patient.pid
          )
          .then((res) => {
            if (res.message == "数据为空") {
              this.$notify.error({
                title: "失败",
                message: "检查数据为空",
              });
            } else if (res.message == "提交检查项目失败") {
              this.$notify.error({
                title: "失败",
                message: "提交检查项目失败",
              });
            } else {
              this.$notify({
                title: "成功",
                message: "提交检查项目成功",
              });
            }
          });
      }
    },
    //最终确诊，全局提交
    submitGlobal(medicalrecord) {
      this.$refs[medicalrecord].validate((valid) => {
        if (valid) {
          //将数据提交
          // 提交之前 判断患者姓名
          let pname = this.patientBean.patient.pname;
          if (pname == "") {
            this.$notify.error({
              title: "错误",
              message: "请输入患者信息",
            });
          } else if (this.checkInspectitemTableList.length == 0) {
            this.$notify.error({
              title: "错误",
              message: "请输入检验项目",
            });
            return false;
          } else if(this. selectcheckitemTableList.length == 0) {
            this.$notify.error({
              title: "错误",
              message: "请输入检查项目",
            });
            return false;
          }
          else {
            //调用 接口 提交
            medicalrecordapi
              .saveGlobal(
                this.medicalrecord,
                this.checkInspectitemTableList,
                this.selectcheckitemTableList,
                this.patientBean.patient.pid
              )
              .then((res) => {
                this.$notify({
                  title: "成功",
                  message: "全局提交成功",
                  type: "success",
                });
              }).then(res=>{
                 this.resetForm3(this.medicalrecord);
              });
              //this.resetForm3(this.medicalrecord);
          }
        }
      });
    },
    //方法体里面
  },
  created() {
    this.getPatientListByStatus1();
    this.getPatientListByStatus3();
  },
  filters: {
    showPrice(value) {
      return "$" + value.toFixed(2);
    },
    showPrice2(value) {
      return "$" + value.toFixed(2);
    },
  },
  computed: {
    totalPrice() {
      let total = 0;
      this.checkInspectitemTableList.forEach((item) => {
        total += item.price * item.amount;
      });
      return total;
    },
     totalPrice2() {
      let total = 0;
      this. selectcheckitemTableList.forEach((item) => {
        total += item.price * item.amount;
      });
      return total;
    }
  },
};
</script>

<style scoped>
#aside {
  border: 5px solid #dcdfe6;
  border-radius: 10px;
  padding: 12px;
}
</style>

